<template>
	<view class="main">
		<u-navbar title="导游认证" :autoBack="true" :placeholder="true" :titleStyle="state.titleStyle" :height="40"
			bgColor="#F5F5F5">
		</u-navbar>
		<view class="buc">
			上传旅游证：
		</view>
		<view class="img">
			<image src="../../static/me_rz_icon_sfz1@2x.png" mode="" v-if="state.fullurl==''" @click="chooseImage"></image>
			<image :src="state.fullurl" mode="" v-else></image>
		</view>
		<view class="butLi" v-if="state.userInfo.guide!='0'" @click="getTi()">
		    提交认证
		</view>
		<!-- <view class="butLi" @click="getTis()" v-else>
		    提交认证
		</view> -->
	</view>
</template>
<script setup>
	import {ref,reactive,} from 'vue';
	import sheep from '@/sheep';
	import {onLoad} from '@dcloudio/uni-app';
	const state = reactive({
		duiId:'',
		fullurl:'',
		userInfo:{}
	});
	onLoad((options) => {
		getguideCon()
		getUser()
	});
	// 倒计时
	function getLeft(){
		uni.navigateBack({
			delta:1,//返回层数，2则上上页
		})
	}
	async function getUser(){
		const {code,data} = await sheep.$api.user.userInfo({
			token:uni.getStorageSync('token'),
		})
		if (code == 1) {
			state.userInfo = data
		}
	}
	// 详情guideCon
	async function getguideCon() {
		const {code,data,msg} = await sheep.$api.user.guideCon({

			token:uni.getStorageSync('token'),
		})
		if (code == 1) {
			state.fullurl=data.con.images
		}else{
			uni.showToast({
				title:msg,
				icon:'none'
			})
		}
	}
	// 修改
	async function getTis() {
		const {code,data,msg} = await sheep.$api.user.guideEdit({
			images:state.fullurl,
			token:uni.getStorageSync('token'),
		})
		if (code == 1) {
		    uni.showToast({
		    	title:'上传成功',
		    	icon:'none'
		    })
		}else{
			uni.showToast({
				title:msg,
				icon:'none'
			})
		}
	}
	//提交
	async function getTi() {
		if (state.fullurl == "") {
		  uni.showToast({
		    title: "请上传导游证",
		    icon: "none",
		    duration: 1000,
		  })
		  return
		}
		const {code,data,msg} = await sheep.$api.user.addGuide({
			images:state.fullurl,
			token:uni.getStorageSync('token'),
		})
		if (code == 1) {
		    uni.showToast({
		    	title:'上传成功',
		    	icon:'none'
		    })
		}else{
			uni.showToast({
				title:msg,
				icon:'none'
			})
		}
	}
// 上传图片
	function chooseImage(){
		uni.chooseImage({
		    count:1, //默认9
		    sizeType: ["compressed"], //可以指定是原图还是压缩图，默认二者都有
		    sourceType: ["album", "camera"], //从相册选择
		    success: (res) => {
				// state.imagePath = res.tempFilePaths[0]	
				// state.preimagePath = res.tempFilePaths
		        uni.uploadFile({
		            url:'https://laiyu.1122334455.cn/api/common/upload', 
		            filePath: res.tempFilePaths[0],
		            name:'file',   
		            formData: {
		                token: uni.getStorageSync('token')
		            },
		            success:(res) => {
		        		var data = JSON.parse(res.data)
						console.log(data)
		        		if(data.code == 1){
		        			state.fullurl=data.data.fullurl
		        		}
		            },
		            fail: (err) => {
		                console.log('uploadImage fail', err);
		            }
		        });
		    },
		});
	}
</script>
<style  lang="scss">
	.butLi{
		width: calc(100% - 64rpx);
		margin:60rpx auto 0;
		position: fixed;
		bottom:40rpx;
		left:32rpx;
		background: #1BDDD0;
		font-size:32rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #FFFFFF;
		line-height: 92rpx;
		text-align: center;
		border-radius: 54rpx;
	}
	page {
		height: 100%;
		width: 100%;
		background-color: #F5F5F5;
		.main {
			height: 100%;
			width: 100%;
			background-color: #F5F5F5;
		}
		.img{
		    width:calc(100% - 48rpx);
		    padding:24rpx;
		    background: #fff;
			margin: 20rpx 0; 
			text-align: center;
			image{
				width: 440rpx;
				height:280rpx;
				// text-align: right;
			}
		}
		.butLi{
			width: calc(100% - 64rpx);
			margin:60rpx auto;
			background: #1BDDD0;
			font-size:32rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color: #FFFFFF;
			line-height: 92rpx;
			text-align: center;
			border-radius: 54rpx;
		}
		.buc{
			width:calc(100% - 64rpx);
			margin: 20rpx auto;
			font-size: 28rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color: #333333;
		}
		.duiHuan{
			width: calc(100% - 64rpx);
			margin:2 0rpx auto;
			font-size: 28rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #666666;
			line-height: 50rpx;
		}
   }
   
</style>
